package com.zmn.oms.task.listener;

import com.alibaba.fastjson.JSON;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.model.dto.fcorderpart.expressage.ExpressageDTO;
import com.zmn.oms.zmn.business.interfaces.part.ZsOrderFactoryPartBService;
import com.zmn.oms.zmn.business.interfaces.work.OrderWorkOrderPostBService;
import com.zmn.tapi.dubbo.interfaces.expressage.ExpressageRemoteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/** 
 * 类描述：快递状态变更订阅
 * 
 * @author  wangwei
 * @date   2019/06/19 20:42
 */
@AliyunMQListener(topic = "${spring.mq.topic.plat}")
@Component
public class OrderPostChangeListener {

    private static final Logger logger = LoggerFactory.getLogger(OrderPostChangeListener.class);

    @Autowired
    ZsOrderFactoryPartBService zsOrderFactoryPartBService;
    @Autowired
    OrderWorkOrderPostBService orderWorkOrderPostBService;

    @AliyunMQHandler(tags = ExpressageRemoteService.TAGS_EXPRESSAGE_UPDATE)
    public void postStatusChange(String message){
        try {
            logger.info("#mq#poststatus#recive message:{}", message);
            ExpressageDTO expressageDTO = JSON.parseObject(message, ExpressageDTO.class);
            zsOrderFactoryPartBService.updatePostStatus(expressageDTO);

            // 更新订单物流信息
            orderWorkOrderPostBService.updateOrderPostExpress(expressageDTO);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
